package cn.kgc.rainmanager.service.impl;

import cn.kgc.rainmanager.mapper.AirQIMapper;
import cn.kgc.rainmanager.pojo.AirQI;
import cn.kgc.rainmanager.pojo.AirQIExample;
import cn.kgc.rainmanager.service.AirService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 陈啸
 */
@Service
public class AirServiceImpl implements AirService {
    @Resource
    AirQIMapper airMapper;
    @Override
    public PageInfo<AirQI> select(Integer pageNum, Integer pageSize, Integer districtId) {
        PageHelper.startPage(pageNum,pageSize);
        List<AirQI> airList;
        if(districtId!=0){
            AirQIExample example=new AirQIExample();
            AirQIExample.Criteria criteria=example.createCriteria();
            criteria.andDistrictidEqualTo(districtId);
            airList=airMapper.selectByExample(example);
        }else{
            airList=airMapper.selectByExample(null);
        }
        PageInfo<AirQI> pageInfo=new PageInfo<>(airList);
        return pageInfo;
    }

    @Override
    public Integer add(AirQI air) {
        int i=airMapper.insert(air);
        return i;
    }

    @Override
    public AirQI selectById(Integer id) {
        AirQI air=airMapper.selectByPrimaryKey(id);
        return air;
    }

    @Override
    public Integer update(AirQI air) {
        int i=airMapper.updateByPrimaryKey(air);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=airMapper.deleteByPrimaryKey(id);
        return i;
    }
}
